/**
 * Message.java
 */
package fss.common.communication;

import java.io.Serializable;
import java.util.Date;

import fss.util.UtcDate;
import fss.util.rmi.RmiId;

/**
 * A message is the communication object between remote objects.
 * <p>
 * It holds various info/error logs for the consumer to use for 
 * traceability and debugging purposes.
 * 
 * @author thinh
 *
 */
public abstract class Message implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * Creation timestamp.
     */
    protected Date timestamp = null;
    /**
     * Source id.
     */
    protected RmiId sourceId = null;
    /**
     * Destination id.
     */
    protected RmiId destinationId = null;
    /**
     * Instantiate a creation timestamp in UTC.
     */
    protected Message() {
        timestamp = (new UtcDate()).getDate();
    }
    /**
     * Instantiate a message with source and desintation identifiers.
     * @param sourceId the source id.
     * @param destinationId the destination id.
     */
    protected Message(RmiId sourceId, RmiId destinationId) {
        this();
        this.sourceId = sourceId;
        this.destinationId = destinationId;
    }
    /**
     * Instantiate a message.
     * @param sourceId the source id.
     */
    protected Message(RmiId sourceId) {
        this();
        this.sourceId = sourceId;
    }
    /**
     * Get the message timestamp.
     * @return the creation timestamp.
     */
    public Date getTimestamp() {
        return timestamp;
    }
    /**
     * Get the source id.
     * @return the id.
     */
    public RmiId getSource() {
        return sourceId;
    }
    public void setSource(RmiId id) {
        sourceId = id;
    }
    /**
     * Get the destination id.
     * <p>
     * This is usually where the source sends the message
     * to and is not necessarily the intended recipient(s).
     * @return the destination id.
     */
    public RmiId getDestination() {
        return destinationId;
    }
    /**
     * Set the destination.
     * @param id the destination id.
     */
    public void setDestination(RmiId id) {
        destinationId = id;
    }
}
